package cn.kgc.jdbc.dao;

import cn.kgc.jdbc.entity.Clazz;
import cn.kgc.jdbc.utils.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author: mosin
 * @version: v1.0  2022/4/22
 */
public class ClazzDaoImpl implements ClazzDao {
    @Override
    public Clazz selectByName(String clazzName) {
        QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
        String sql = "select id,class_name AS className from clazz where class_name = ?";
        try {
            Clazz clazz = queryRunner.query(sql, new BeanHandler<>(Clazz.class), clazzName);
            return  clazz;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
